﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using Rison.Web.Common;
using Rison.BusinessFacade.Entity.Biz;
using Rison.BusinessFacade.Facade.Biz;
using Rison.BusinessFacade.Common;
using Rison.BusinessFacade.Helper;
namespace Rison.Web.view
{
    public partial class InfoBrowseView : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request.QueryString["key"]))
                    LoadInfo();
            }
        }


        private void LoadInfo()
        {
            string infoId = Request.QueryString["key"];

            InfosReaderFacade facade = new InfosReaderFacade("gg");

            DataRow row = facade.ReadInfomation(infoId);
            if (row != null)
            {
                labSubject.Text = StringHelper.GetValue(row, "title");
                labRQ.Text = Convert.ToDateTime(row["showtime"]).ToString("yyyy年MM月dd日");
                labContent.Text = StringHelper.GetValue(row, "content");
                if (StringHelper.GetValue(row, "MediaFileName") != "")
                {
                    if (StringHelper.GetValue(row, "MediaFileName").StartsWith("/"))
                    {
                        Image1.ImageUrl = GlobalParams.Instance.NewsImageBaseUrl + StringHelper.GetValue(row, "MediaFileName");
                    }
                    else
                    {
                        Image1.ImageUrl = GlobalParams.Instance.NewsImageBaseUrl + "/" + StringHelper.GetValue(row, "MediaFileName");
                    }
                }
                else
                {
                    Image1.Visible = false;
                }

                DataSet ds = facade.ReadAttachment(infoId);
                this.labAtt.Text = "";
                foreach (DataRow dr in ds.Tables[0].Rows)
                {                
                    string url="";
                    this.labAtt.Text = "";

                    if (StringHelper.GetValue(dr, "DisplayFileName") != "" & StringHelper.GetValue(dr, "PhysicalFileUrl") != "")
                    {
                        if (StringHelper.GetValue(dr, "PhysicalFileUrl").StartsWith("/"))
                        {
                            url = GlobalParams.Instance.NewsImageBaseUrl + StringHelper.GetValue(dr, "PhysicalFileUrl");
                        }
                        else
                        {
                            url = GlobalParams.Instance.NewsImageBaseUrl + "/" + StringHelper.GetValue(dr, "PhysicalFileUrl");
                        }
                        this.labAtt.Text += "<a href='" + url + "' target='_blank'>" + StringHelper.GetValue(dr, "DisplayFileName") + "</a></br>";
                    }
                }
            }
            else
            {
                //最新诉求、最新回复
                //facade = new InfosReaderFacade("zxsq");
                //row = facade.ReadSuqiuDetail(infoId);

                //if (row != null)
                //{
                //    labSubject.Text = StringHelper.GetValue(row, "title");
                //    labRQ.Text = Convert.ToDateTime(row["showtime"]).ToString("yyyy年MM月dd日");
                //    labContent.Text = StringHelper.GetValue(row, "content");
                //}
            }
        }


        public string NavUrl
        {
           get
            {
                //return string.IsNullOrEmpty(Request.QueryString["t"]) ? "gg" : "公告" ;
                if (!string.IsNullOrEmpty(Request.QueryString["t"]))
                {
                    string url = Request.QueryString["t"].ToString();
                    if (url == "gg") return "公告";
                    if (url == "jfdt") return "纠风动态";
                    if (url == "jfhc") return "纠风荟萃";
                    if (url == "zxzl") return "专项治理";
                    if (url == "zspy") return "站所评议";
                    if (url == "jftp") return "图片新闻";
                    if (url == "ftsl") return "访谈实录";
                }

                return "纠风信息";

            }
        }
    }
}
